package cn.bdqn.controller;

import cn.bdqn.bean.result.Page;
import cn.bdqn.bean.result.Result;
import cn.bdqn.bean.result.ResultGenerator;
import cn.bdqn.domain.Storage;
import cn.bdqn.domain.Storagedan;
import cn.bdqn.service.StoragedanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/PMS/storagedan")
public class StoragedanController {
    @Autowired
    private StoragedanService storagedanService;
/*
   分页显示
   查看仓库全部信息
   startNum 第几页
 */
    @GetMapping("/queryAll")
    public Result queryAll(Integer startNum){
        Page page=storagedanService.queryAll(startNum);
        return ResultGenerator.genSuccessResult(page);
    }
    /*
     分页显示
     多条件查询仓库药品信息
     startNum 第几页
     */
    @GetMapping("/queryByStoragedan")
    public Result queryByStoragedan(Integer startNum,Storagedan storagedan){
        try{
            storagedan.setDanName("安");
            Page page= storagedanService.queryByStoragedan(startNum,storagedan);
            return ResultGenerator.genSuccessResult(page);
        }catch (Exception e){
            e.printStackTrace();
            return ResultGenerator.genFailResult("查询失败");
        }
    }
    /*
     添加药品信息
     */
      @PostMapping("/save")
    public Result save(Storagedan storagedan){
          try {
              storagedanService.save(storagedan);
              return ResultGenerator.genSuccessResult(storagedan.getDanName()+"添加成功");
          }catch (Exception e){
              e.printStackTrace();
              return ResultGenerator.genFailResult(storagedan.getDanName()+"添加失败");
          }
      }
      /*
       修改药品信息
       */
      @PostMapping("/update")
      public Result update(Storagedan storagedan){
          try {
              storagedanService.update(storagedan);
              return ResultGenerator.genSuccessResult(storagedan.getDanName()+"修改成功");
          }catch (Exception e){
              e.printStackTrace();
              return ResultGenerator.genFailResult(storagedan.getDanName()+"修改失败");
          }
      }
      /*
       删除药品信息
       */
    @PostMapping("/delete")
    public Result delete(Integer id){
        try {
            storagedanService.delete(id);
            return ResultGenerator.genSuccessResult("删除成功");
        }catch (Exception e){
            e.printStackTrace();
            return ResultGenerator.genFailResult("删除失败");
        }
    }
    /*
     获取药房申请表里面的药品信息列表
     */


}
